01. If Statements

If Statements

Question:

Start Quiz:

Solution:

INSTRUCTOR NOTE:

Strict equality (===) vs Loose equality (==)

When you use three equal signs, ===, no type conversion is done prior to the comparison. If the values are different types, for example, a String and a Number, they can't ever be equal. To return true, the values must be equal and the types must be the same.

Loose equality, ==, checks to see if the two values are the same type and if not, converts to a common type before the conversion. If the types are already the same, there is no difference between the result of === and ==. When they aren't it can cause unexpected results.

Check the link to an article on Mozilla Developer Network to see what values get converted into what.

According to Jacques Favreau, the lead front-end engineer at Udacity, you should never use ==. It's a frequent source of bugs. In fact, if a Udacity engineer tries to commit code with ==, it automatically gets rejected.

Though it wasn't mentioned in the video, the same conditions apply for strict inequality (!==) and loose inequality (!=). Loose inequality is more forgiving than loose equality so you might not see strict inequality as often.



For this quiz you'll work with the index.htmland js/resumeBuilder.js files from the résumé project's Github repository you downloaded earlier in this lesson. Edit js/resumeBuilder.js in your text editor, and view the results by opening index.html in the browser of your choice.

Skills not displaying in resume?

This if statement in index.html prevents anything from displaying within the #header element when there is no h1 element in the document.

    if (document.getElementsByTagName('h1').length === 0) {
        document.getElementById('header').style.display = 'none';
    }

The following variable in the helper.js file contains an h1 element:

var HTMLheaderName = '<h1 id="name">%data%</h1>';

If the %data% substring in the HTMLheaderName variable is replaced with the bio.name property and the result is appended to the #header element, skills can then appear because the if statement in index.html will no longer be true.




Follow your instructors!

@cwpittman

+jameswilliams